﻿<!DOCTYPE html>
<html>
<head>
    <title>CGI</title>
</head>
<body>
    <h1>Our Page</h1>
    <script>
        //01
        //for floating point calculation, we should use toFixed
        
        var total = 30 - 20;
        console.log(total);

        var total = 3.8 - 2.1;
        console.log(total);

        var total = 3.8 - 2.1;
        console.log(total.toFixed(3));
         

        //02
        //JS sees the minus sign and everything converts to numeric, implicit conversion occurs
        /*
        var total = "300" - "200";
        console.log(total);

        var total = "PRD300" - "ITEM200";
        console.log(total);

        var total = 300 - undefined;
        console.log(total);

        //null treated as 0
        var total = 300 - null;
        console.log(total);

        var total=300 - NaN;
        console.log(total);

        //empty string converted into zero
        var total=300 - "";
        console.log(total);
        */

        //03
        //object variable value return through function & assign to 'valueOf' property
        /*
        var obj = {
            valueOf: function () { return 100; }
        };

        var total = 300 - obj;
        console.log(total);
         */
    </script>
</body>
</html>